package csci6450.chickenFriedFS.metaServer;

import csci6450.chickenFriedFS.metaServer.threads.MetaServerClientListener;
import csci6450.chickenFriedFS.metaServer.threads.MetaServerNuggetServerListener;
import csci6450.chickenFriedFS.metaServer.threads.ReplicationManager;
import csci6450.chickenFriedFS.nuggetCore.ChickenFile; 
import csci6450.chickenFriedFS.nuggetCore.Nugget; 
import csci6450.chickenFriedFS.nuggetCore.NuggetLog; 
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.F82F170C-C0FC-80DC-F6BD-BBB2DAB56532]
// </editor-fold> 
public class MetaServer {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F36AD5E4-8F68-35F3-AA6C-B77348EF18ED]
    // </editor-fold> 
    private NuggetLog nuggetLog;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.157B7934-E79A-DD99-1837-0C3210091F4B]
    // </editor-fold> 
    private List<ChickenFile> chickenFiles;

    private MetaServerClientListener clientListener;
    private MetaServerNuggetServerListener nuggetServerListener;
    private ReplicationManager replicationManager;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.1209E42B-7357-2487-6775-53B27EAA68E2]
    // </editor-fold> 
    private MetaServer () {
        try {
            this.clientListener = new MetaServerClientListener();
            this.nuggetServerListener = new MetaServerNuggetServerListener();
            this.replicationManager = new ReplicationManager();
        } catch (IOException ex) {
            Logger.getLogger(MetaServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private static MetaServer metaServer = new MetaServer();


    public static MetaServer getInstance(){
        return metaServer;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.744856A9-BFDF-980D-5F5C-65BAD3F6C43E]
    // </editor-fold> 
    public void start () {
        this.clientListener.start();
        this.nuggetServerListener.start();
        this.replicationManager.start();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F5083C50-D5F1-8461-B680-CDAECB40683A]
    // </editor-fold> 
    public void stop () {
        System.out.println("Stopping the Meta Server.");
        System.exit(0);
    }

    /**
     *  <p style="margin-top: 0">
     *        returns a clone() of the List&lt;ChickenFile&gt;
     *      </p>
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.CD0E6325-4883-C898-E144-D4A1E8F8CADA]
    // </editor-fold> 
    public List<ChickenFile> getChickenFiles () {
        return chickenFiles;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.3C900968-E3E4-C4C2-64B4-AF15FD32CB78]
    // </editor-fold> 
    public void setChickenFiles (List<ChickenFile> val) {
        this.chickenFiles = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.E6424FBA-A4D0-E38A-0B92-DC6BECA28C63]
    // </editor-fold> 
    public NuggetLog getNuggetLog () {
        return nuggetLog;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.8BCF8DB4-31E1-D134-71E7-45850CCF685E]
    // </editor-fold> 
    public void setNuggetLog (NuggetLog val) {
        this.nuggetLog = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0CE93ADA-AB1A-A561-0817-4C98E41AFE31]
    // </editor-fold> 
    public ChickenFile getChickenFile (String fileName) {
        return null;
    }

    /**
     *  <p style="margin-top: 0">
     *        Checks if there is an existing ChickenFile with the nugget's 
     *        parentFileName. If there is it updates that chicken file, otherwise it 
     *        creates a new chicken file with the nugget.  Adds nugget to chicken file.
     *      </p>
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.9023794A-9761-C78B-A91B-CB1F12028115]
    // </editor-fold> 
    public void addChickenNugget (Nugget nugget) {
    }

}

